﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using DeviceInfoManage.BusinessLogicLayer;
public partial class DeviceRepairBack : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {   
        /*首次进入本页时需要查询该设备维修记录的相关字段并显示出来*/
        if(!IsPostBack)
        {
            if (Session["adminUserName"] == null)
            {
                Response.Redirect("login.aspx");
            }
            /*取得维修记录编号*/
            string repairId = Request.QueryString["repairId"];
            RepairInfo repairInfo = new RepairInfo();
            /*根据维修记录编号得到该维修记录各个字段信息*/
            repairInfo.GetRepairInfo(Int32.Parse(repairId));
            this.DeviceName.Text = (new DeviceInfo()).GetDeviceName(Convert.ToInt32(repairInfo.DeviceId));
            this.DeviceTypeName.Text = (new DeviceType()).GetDeviceType(Convert.ToInt32(repairInfo.DeviceId));
            this.RepairPlace.Text = repairInfo.RepairPlace;
            this.RepairMan.Text = repairInfo.RepairMan;
            this.ErrReason.Text = repairInfo.ErrReason;
            this.RepairMemo.Text = repairInfo.RepairMemo;
            /*取得该设备的图片路径，如果存在图片就显示*/
            string deviceImagePath = (new DeviceInfo()).GetDeviceImagePath(repairInfo.DeviceId);
            if (deviceImagePath != "")
                this.DeviceImage.ImageUrl = deviceImagePath;
            else
                this.DeviceImage.ImageUrl = "images\\NoImage.jpg";
        }
    }

   
    /*设备返修时完善维修相关信息*/
    protected void Btn_RepairBack_Click(object sender, EventArgs e)
    {

        /*首先对类传入要更新的各个字段信息*/
        RepairInfo repairInfo = new RepairInfo();
        repairInfo.RepairId = Convert.ToInt32(Request.QueryString["repairId"]);
        repairInfo.RepairMan = this.RepairMan.Text;
        repairInfo.ErrReason = this.ErrReason.Text;
        repairInfo.RepairEndTime = Convert.ToDateTime(this.RepairEndTime.Text);
        repairInfo.RepairTime = Convert.ToSingle(this.RepairTime.Text);
        repairInfo.RepairMoney = Convert.ToSingle(this.RepairMoney.Text);
        repairInfo.RepairMemo = this.RepairMemo.Text;
        /*然后调用业务层更新函数对维修信息进行完善*/
        if (repairInfo.UpdateRepairInfo())
            Response.Write("<script>alert('设备返修成功!');location.href='DeviceRepairList.aspx';</script>");

    }
}
